<?php
namespace App\Http\Requests;

class BannerRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            case 'POST':
                return [
                    'title' => 'required|max:255',
                    'img' => 'required|max:255',
                    'url' => 'nullable|max:255',
                ];
                break;
            case 'PUT':
                return [
                    'title' => 'required|max:255',
                    'img' => 'required|max:255',
                    'url' => 'nullable|max:255',
                ];
                break;
        }
    }


    public function messages()
    {
        return [
            'title.required' => '幻灯片标题必填',
            'title.max' => '标题长度超过255个字符',
            'img.required' => '请选择或者上传图片',
        ];
    }

}